package cn.com.sueframe.action;

import java.util.Map;

import cn.com.sueframe.common.CmsConst;
import cn.com.sueframe.exception.ApplicationException;


public class CeswitchAction extends BaseActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 6355105502290007838L;
	private String key = "";
	
	/**
	 * 中英文切换
	 * @return
	 * @author anmin
	 * Create 2013-3-18
	 */
	public String ceswicth() throws ApplicationException{
		try{
			init();
			switchLanguage();
			clearCache();
		}catch(Exception e){
			new ApplicationException(e);
			return CmsConst.FAILURE;
		}
		return CmsConst.SUCCESS;
	}
	/**
	 * 查找当前系统的语言信息
	 * @author anmin
	 * @return void
	 * Created Apr 14, 2013
	 */
	public void findCurLanguge(){
		init();
		String language = this.getCurrentLanguage();
		this.ajaxJsonResponse(language);
	}
	
	
	/**
	 * 如果是语言转换的话，就清除页面缓存
	 * @author anmin
	 * Create 2013-3-22
	 */
	private void clearCache(){
		servletResponse.setHeader("Cache-Control", "no-cache");
		servletResponse.setDateHeader("Expires", 0);
		servletResponse.setHeader("Pragma", "No-cache");
	}
	/**
	 * 根据key值得到国际化的value值
	 * @return
	 * @author anmin
	 * Create 2013-4-6
	 */
	@SuppressWarnings(value="unchecked")
	public void findValueByKey(){
		init();
		String language = this.getCurrentLanguage();
		Map<String,Object> nationalMap = null;
		if("CN".equals(language)){
			nationalMap = (Map<String, Object>)application.getAttribute("cnMap");
		}else{
			nationalMap = (Map<String, Object>)application.getAttribute("enMap");
		}
		Object keyObj = nationalMap.get(key);
		String value = "";
		if(keyObj == null){
			value = key;
		}else{
			value = String.valueOf(keyObj);
		}
		value = value == null || "null".equals(value) || "".equals(value)? key : value;
		super.ajaxResponse(value);
	}
	
	public String getKey() {
		return key;
	}
	
	public void setKey(String key) {
		this.key = key;
	}
	
	
	
	
}
